# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=tootik
pkgver=0.10.4
pkgrel=0
pkgdesc="Federated nanoblogging service with Gemini frontend"
url="https://github.com/dimkr/tootik"
arch="all"
license="Apache-2.0"
depends_openrc="openssl"
makedepends="go"
install="$pkgname.pre-install"
pkgusers="tootik"
pkggroups="tootik"
subpackages="$pkgname-openrc"
source="https://github.com/dimkr/tootik/archive/refs/tags/$pkgver/tootik-$pkgver.tar.gz
	tootik.cfg
	tootik.initd
	tootik.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

export CGO_ENABLED=1
export _GOTAGS="fts5"

build() {
	local _goldflags="
		-X github.com/dimkr/tootik/buildinfo.Version=$pkgver
		"

	go generate -v ./migrations
	go vet -v -tags "$_GOTAGS" ./...
	go build -v -ldflags "$_goldflags" -tags "$_GOTAGS" ./cmd/tootik
}

check() {
	./tootik --version

	# cleanup sqlite database files used by test/register_test.go
	rm -vf /tmp/TestRegister*.sqlite3

	go test -v -tags "$_GOTAGS" -timeout 30m ./...
}

package() {
	install -Dm755 tootik -t "$pkgdir"/usr/bin/
	install -dm750 -o tootik -g tootik "$pkgdir"/var/lib/tootik

	install -dm750 -o tootik -g tootik "$pkgdir"/etc/tootik
	install -Dm640 -o tootik -g tootik "$srcdir"/tootik.cfg \
		-t "$pkgdir"/etc/tootik/

	install -Dm755 "$srcdir"/tootik.initd "$pkgdir"/etc/init.d/tootik
	install -Dm644 "$srcdir"/tootik.confd "$pkgdir"/etc/conf.d/tootik
}

sha512sums="
827317c0b9e968bd1a2dac3c09cf4e24b20c40d7c21a7e9b2328ddc6d7cdf5c574bbe28df2e385e7748ebb5db51dec77944f2ccc53337f57a8a0a5f56f3b2316  tootik-0.10.4.tar.gz
2e106abb178f0918a18c48039f46d8de8886a1c5457ddc735de152da75b561a9f4c4c5e89955becc3edeceea3f8e80285593183a277c9ada6122c872dfb29114  tootik.cfg
7999e43dc50604cc0d0d97292aed9ee5fc658b08b46fc4d92b21916246ee43b54b79ba9306b6196ac8b86d6d53498266a499cd31e90f22749f78bc5d5c404b19  tootik.initd
11fa51d25baaeb295c80cf3e154eb1eab67f9633e23f01cc0a25c427af368746d536bff17de2153b5be925489e3f84ca5ba492a4a43c32aaf33b8c4d00d14fd6  tootik.confd
"
